|
1
|
|
|
import { useSelector } from 'react-redux'; |
|
2
|
|
|
|
|
3
|
|
|
import { RootState } from '../redux/store/store'; |
|
4
|
|
|
import axios from 'axios'; |
|
5
|
|
|
import { API_URL, getHeader } from '../helpers/config'; |
|
6
|
|
|
|
|
7
|
|
|
import { Link } from 'react-router-dom'; |
|
8
|
|
|
import logo from '../assets/images/scooters.webp'; |
|
9
|
|
|
import { Navbar, Button, Popover } from "flowbite-react"; |
|
10
|
|
|
import Logout from './Logout'; |
|
11
|
|
|
import Login from './Login'; |
|
12
|
|
|
|
|
13
|
|
|
export default function Header() { |
|
14
|
|
|
|
|
15
|
4 |
|
const {isLoggedIn, token, user, role} = useSelector((state: RootState) => state.auth); |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
2 |
|
const getAuthStatus = async () => { |
|
19
|
|
|
const response = await axios.get(`${API_URL}/auth/status`, getHeader(token)); |
|
20
|
|
|
console.log(response); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
2 |
|
const getAuthMe = async () => { |
|
24
|
|
|
const response = await axios.get(`${API_URL}/auth/me`, getHeader(token)); |
|
25
|
|
|
console.log(response); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
2 |
|
return ( |
|
29
|
|
|
<> |
|
30
|
|
|
<Navbar fluid rounded> |
|
31
|
|
|
|
|
32
|
|
|
<Navbar.Brand as={Link} to="/"> |
|
33
|
|
|
<img src={logo} className="h-8" alt="Logo" /> |
|
34
|
|
|
<span className="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Hemåt</span> |
|
35
|
|
|
</Navbar.Brand> |
|
36
|
|
|
<Navbar.Toggle /> |
|
37
|
|
|
|
|
38
|
|
|
<Navbar.Collapse> |
|
39
|
|
|
<Navbar.Link as={Link} to="/"> |
|
40
|
|
|
Home |
|
41
|
|
|
</Navbar.Link> |
|
42
|
|
|
{ role =="admin" && <Navbar.Link as={Link} to="/adminstartpage">Adminsida</Navbar.Link>} |
|
43
|
|
|
{ isLoggedIn && |
|
44
|
|
|
<> |
|
45
|
|
|
<Navbar.Link as={Link} to="/customerstartpage">Kundsida</Navbar.Link> |
|
46
|
|
|
<Logout className="px-1 py-0.5" size="xs"></Logout> |
|
47
|
|
|
</> |
|
48
|
|
|
} |
|
49
|
|
|
{ |
|
50
|
|
|
!isLoggedIn && |
|
51
|
|
|
<Login className="px-1 py-0.5" size="xs"/> |
|
52
|
|
|
} |
|
53
|
|
|
</Navbar.Collapse> |
|
54
|
|
|
</Navbar> |
|
55
|
|
|
|
|
56
|
|
|
<div className='flex justify-center items-center'> |
|
57
|
|
|
<div className="text-xs block max-w-sm p-6 h-40 overflow-scroll bg-white border border-gray-200 rounded-lg shadow"> |
|
58
|
|
|
|
|
59
|
|
|
<p className="text-gray-700 dark:text-gray-400">Logged In: <b>{isLoggedIn.toString()}</b></p> |
|
60
|
|
|
<p className="text-gray-700 dark:text-gray-400">Role: <b>{role}</b></p> |
|
61
|
|
|
<p className="text-gray-700 dark:text-gray-400">User: <b>{user ? JSON.stringify(user) : "No User"}</b></p> |
|
62
|
|
|
<Popover aria-labelledby="default-popover" content={<p>{token ? token : "Empty"} </p>}> |
|
63
|
|
|
<Button color="warning" size="xs" onClick={() => console.log(token)}>Klicka här för token</Button> |
|
64
|
|
|
</Popover> |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
<Button color="warning" size="xs" onClick={getAuthStatus}>Prompt auth/status in console</Button> |
|
68
|
|
|
<Button color="warning" size="xs" onClick={getAuthMe}>Prompt auth/me in console</Button> |
|
69
|
|
|
</div> |
|
70
|
|
|
</div> |
|
71
|
|
|
|
|
72
|
|
|
</> |
|
73
|
|
|
) |
|
74
|
|
|
}; |
|
75
|
|
|
|